import time
from decimal import Decimal
import numpy as np
from flask import jsonify
from redis import Redis
import math
client = Redis(host='localhost', port=6379, decode_responses=True)
value = [0, 0, 0, 0]
t=[0]
#获取当前时间
def get_time():
    time_str = time.strftime("%Y{}%m{}%d{} %X")
    return time_str.format("年","月","日")

def get_c1_data():
    OrderTotal = client.get("orderNum")
    PriceTotal = client.get("total")
    RecTotal = client.zcard("custorm")
    PriceTotal= int(float(PriceTotal))
    OrderTotal=int(OrderTotal)
    value[0] = PriceTotal
    value[1] = OrderTotal
    value[2] = RecTotal
    return value

def get_l2_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    type = client.zrevrange('china', 0, 9, withscores=True)
    return type

def get_l1_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    data = client.zrevrange('PayMethod', 0, -1, withscores=True)
    # type_list, value_list = ["", "", ""], ["", "", ""]
    # data=np.array(data)
    # for i in range(3):
    #     type_list[i] = data[i][0]
    #     value_list[i] = data[i][1]
    # print(type_list)
    # data1 = {"value": type_list[0], "name": value_list[0]}
    # data2 = {"value": type_list[1], "name": value_list[1]}
    # data3 = {"value": type_list[2], "name": value_list[2]}
    # print(data1)
    return data

def get_r2_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    type = client.zrevrange('PressRank', 0, 9, withscores=True)
    return type

def get_r1_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    type = client.zrevrange('BookRank', 0, 9, withscores=True)
    return type

def get_c2_data():
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    # province = client.get("OrderTotal")
    province = client.zrange('Province', 0, -1, withscores=True, desc=True)
    # print(province)
    return province


if __name__ == '__main__':
    print(get_time())
    # client = Redis(host='localhost', port=6379, decode_responses=True)
    # key = "OrderTotal"
    # value = client.get("%s" %key)
    # print(get_r1_data())